#include <iostream>
#include <cmath>
#include <unordered_map>
#include <string>

bool is_prime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(n)) + 1; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int closest_prime(int num) {
    int offset = 0;
    while (true) {
        if (is_prime(num - offset)) {
            return num - offset;
        } else if (is_prime(num + offset)) {
            return num + offset;
        }
        offset += 1;
    }
}

int main() {
    std::unordered_map<std::string, int> words_to_numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::string input;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    std::string word;
    std::vector<std::string> input_words;
    while (iss >> word) {
        input_words.push_back(word);
    }

    if (input_words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }

    int number = 0;
    for (const auto& word : input_words) {
        if (words_to_numbers.find(word) == words_to_numbers.end()) {
            std::cout << "Wrong input" << std::endl;
            return 1;
        }
        number = number * 10 + words_to_numbers[word];
    }

    std::cout << closest_prime(number) << std::endl;

    return 0;
}

